package com.bifrost.entity;

import com.bifrost.constant.CouponAuthStatus;
import org.hibernate.annotations.DynamicUpdate;

import java.io.Serializable;
import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the COUPON database table.
 *
 * @author joewee
 */
@Entity
@Table(name="COUPON",indexes = {
       @Index(name = "REDEEM_CODE_INDEX",columnList = "REDEEM_CODE",unique = false)
})
@NamedQuery(name="Coupon.findAll", query="SELECT c FROM Coupon c")
@DynamicUpdate
public class Coupon implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="COUPON_ID", unique=true, nullable=false)
	private Long couponId;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="ACTIVE_END_DATE")
	private Date activeEndDate;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="ACTIVE_START_DATE")
	private Date activeStartDate;

	@Column(name="COUPON_DESCRIPTION", length=255)
	private String couponDescription;

	@Column(name="COUPON_NAME", length=100)
	private String couponName;

	@Column(name="COUPON_QUANTITY",precision=11)
	private Integer couponQuantity=0;

	@Column(name = "FOR_ORDER_TYPE")
    private String forOrderType;

	@Column(name = "VALIDITY_TYPE",length = 64)
	private String validityType;

	@Column(name = "VALIDITY_DAYS",precision = 11)
	private  Integer validityDays=0;
	@Column(name = "DISCOUNT_TYPE",length = 64)
    private String discountType;
	@Column(name="DISCOUNT_AMOUNT", precision=19, scale=5)
	private BigDecimal discountAmount=BigDecimal.ZERO;

	@Column(name="IS_COMBINABLE")
	private Boolean isCombinable=Boolean.FALSE;

	@Column(name="IS_ENABLED")
	private Boolean isEnabled=Boolean.TRUE;

	@Column(name="IS_REFUNDABLE")
	private Boolean isRefundable=Boolean.FALSE;

	@Column(name="IS_SHAREABLE")
	private Boolean isShareable=Boolean.FALSE;

	@Column(name="MAX_USE_PER_ORDER")
	private Integer maxUsePerOrder=1;

	@Column(name="MAX_USES_PER_CUSTOMER")
	private Integer maxUsesPerCustomer=1;

/*	@Column(name="MERCHANT_ID")
	private Long merchantId;*/

	@Column(name="ORDER_MIN_TOTAL", precision=19, scale=5)
	private BigDecimal orderMinTotal;

	@Column(name="QUANTITY_AVAILABLE",precision=11,nullable = false)
	private Integer quantityAvailable=0;

	@Column(name="RELATED_TARGET_QUANTITY", precision=11)
	private Integer relatedTargetQuantity;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="RELEASE_BY")
	private MerchantStore releaseBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="RELEASE_DATE_END")
	private Date releaseDateEnd;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="RELEASE_DATE_START")
	private Date releaseDateStart;

	@Column(name="RELEASE_MODE", length=32)
	private String releaseMode;

	@Column(name="STACKED_WITH_OTHER")
	private Boolean stackedWithOther;

	@Column(name="TIMES_USED",nullable = false)
	private Integer timesUsed = 0;

	@Column(name="UPDATED_BY", length=64)
	private String updatedBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="UPDATED_TIMESTAMP")
	private Date updatedTimestamp;


	@Column(name="COUPON_TYPE_CODE",length = 64)
	private String couponTypeCode;
	@Column(name = "REDEEM_CODE",length = 32)
	private String redeemCode;
	/**
     * 外部规则码
     * */
    @Column(name = "RULE_CODE",length = 32)
    private String ruleCode;
    /**
     * 券标识
     * */
    @Column(name = "FLAG",length = 16)
    private String flag;
	//bi-directional many-to-one association to Media
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="MEDIA_ID")
	private Media media;

	//bi-directional many-to-one association to CouponAttribute
	@OneToMany(mappedBy="coupon")
	private List<CouponAttribute> couponAttributes;

	@OneToMany(mappedBy = "coupon")
    private List<CouponMerchant> couponMerchants;

	@OneToMany(mappedBy="coupon")
	private List<CouponDetail> couponDetails;

	@OneToMany(mappedBy="coupon")
	private List<CouponRule> couponRules;

    //bi-directional many-to-one association to CouponExclude
    @OneToMany(mappedBy="coupon")
    private List<CouponExclude> couponExcludes;
    /**
     * 兑换所需积分
     * */
    @Column(name = "BONUS_POINTS")
    private BigInteger bonusPoints = BigInteger.ZERO;
	/**
	 * 购买所需金额
	 */
	@Column(name = "PRICE")
	private BigDecimal price = BigDecimal.ZERO;

	@Column(name = "AUTH_STATUS", length = 64)
	private String authStatus = CouponAuthStatus.UNAUTH;

	/*@OneToMany(mappedBy="coupon")
	private List<InsuranceGiftwrapItem> insuranceGiftwrapItems;*/

	public Coupon() {
	}

	public Long getCouponId() {
		return this.couponId;
	}

	public void setCouponId(Long couponId) {
		this.couponId = couponId;
	}

	public Date getActiveEndDate() {
		return this.activeEndDate;
	}

	public void setActiveEndDate(Date activeEndDate) {
		this.activeEndDate = activeEndDate;
	}

	public Date getActiveStartDate() {
		return this.activeStartDate;
	}

	public void setActiveStartDate(Date activeStartDate) {
		this.activeStartDate = activeStartDate;
	}

	public String getCouponDescription() {
		return this.couponDescription;
	}

	public void setCouponDescription(String couponDescription) {
		this.couponDescription = couponDescription;
	}

	public String getCouponName() {
		return this.couponName;
	}

	public void setCouponName(String couponName) {
		this.couponName = couponName;
	}

	public Integer getCouponQuantity() {
		return this.couponQuantity;
	}

	public void setCouponQuantity(Integer couponQuantity) {
		this.couponQuantity = couponQuantity;
	}

    public String getValidityType() {
        return validityType;
    }

    public void setValidityType(String validityType) {
        this.validityType = validityType;
    }

    public Integer getValidityDays() {
        return validityDays;
    }

    public void setValidityDays(Integer validityDays) {
        this.validityDays = validityDays;
    }

    public String getCouponTypeCode() {
        return couponTypeCode;
    }

    public void setCouponTypeCode(String couponTypeCode) {
        this.couponTypeCode = couponTypeCode;
    }

    public String getDiscountType() {
        return discountType;
    }

    public void setDiscountType(String discountType) {
        this.discountType = discountType;
    }

    public String getForOrderType() {
        return forOrderType;
    }

    public void setForOrderType(String forOrderType) {
        this.forOrderType = forOrderType;
    }

    public BigDecimal getDiscountAmount() {
		return this.discountAmount;
	}

	public void setDiscountAmount(BigDecimal discountAmount) {
		this.discountAmount = discountAmount;
	}

	public Boolean getIsCombinable() {
		return this.isCombinable;
	}

	public void setIsCombinable(Boolean isCombinable) {
		this.isCombinable = isCombinable;
	}

	public Boolean getIsEnabled() {
		return this.isEnabled;
	}

	public void setIsEnabled(Boolean isEnabled) {
		this.isEnabled = isEnabled;
	}

	public Boolean getIsRefundable() {
		return this.isRefundable;
	}

	public void setIsRefundable(Boolean isRefundable) {
		this.isRefundable = isRefundable;
	}

	public Boolean getIsShareable() {
		return this.isShareable;
	}

	public void setIsShareable(Boolean isShareable) {
		this.isShareable = isShareable;
	}

	public Integer getMaxUsePerOrder() {
		return this.maxUsePerOrder;
	}

	public void setMaxUsePerOrder(Integer maxUsePerOrder) {
		this.maxUsePerOrder = maxUsePerOrder;
	}

	public Integer getMaxUsesPerCustomer() {
		return this.maxUsesPerCustomer;
	}

	public void setMaxUsesPerCustomer(Integer maxUsesPerCustomer) {
		this.maxUsesPerCustomer = maxUsesPerCustomer;
	}

	public BigDecimal getOrderMinTotal() {
		return this.orderMinTotal;
	}

	public void setOrderMinTotal(BigDecimal orderMinTotal) {
		this.orderMinTotal = orderMinTotal;
	}

	public Integer getQuantityAvailable() {
		return this.quantityAvailable;
	}

	public void setQuantityAvailable(Integer quantityAvailable) {
		this.quantityAvailable = quantityAvailable;
	}

	public Integer getRelatedTargetQuantity() {
		return this.relatedTargetQuantity;
	}

	public void setRelatedTargetQuantity(Integer relatedTargetQuantity) {
		this.relatedTargetQuantity = relatedTargetQuantity;
	}

	public MerchantStore getReleaseBy() {
		return this.releaseBy;
	}

	public void setReleaseBy(MerchantStore releaseBy) {
		this.releaseBy = releaseBy;
	}

	public Date getReleaseDateEnd() {
		return this.releaseDateEnd;
	}

	public void setReleaseDateEnd(Date releaseDateEnd) {
		this.releaseDateEnd = releaseDateEnd;
	}

	public Date getReleaseDateStart() {
		return this.releaseDateStart;
	}

	public void setReleaseDateStart(Date releaseDateStart) {
		this.releaseDateStart = releaseDateStart;
	}

	public String getReleaseMode() {
		return this.releaseMode;
	}

	public void setReleaseMode(String releaseMode) {
		this.releaseMode = releaseMode;
	}

	public Boolean getStackedWithOther() {
		return this.stackedWithOther;
	}

	public void setStackedWithOther(Boolean stackedWithOther) {
		this.stackedWithOther = stackedWithOther;
	}

	public Integer getTimesUsed() {
		return this.timesUsed;
	}

	public void setTimesUsed(Integer timesUsed) {
		this.timesUsed = timesUsed;
	}

	public String getUpdatedBy() {
		return this.updatedBy;
	}

	public void setUpdatedBy(String updatedBy) {
		this.updatedBy = updatedBy;
	}

	public Date getUpdatedTimestamp() {
		return this.updatedTimestamp;
	}

	public void setUpdatedTimestamp(Date updatedTimestamp) {
		this.updatedTimestamp = updatedTimestamp;
	}

	public Media getMedia() {
		return this.media;
	}

	public void setMedia(Media media) {
		this.media = media;
	}

    public String getRedeemCode() {
        return redeemCode;
    }

    public void setRedeemCode(String redeemCode) {
        this.redeemCode = redeemCode;
    }

    public String getRuleCode() {
        return ruleCode;
    }

    public void setRuleCode(String ruleCode) {
        this.ruleCode = ruleCode;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public List<CouponAttribute> getCouponAttributes() {
		return this.couponAttributes;
	}

	public void setCouponAttributes(List<CouponAttribute> couponAttributes) {
		this.couponAttributes = couponAttributes;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public CouponAttribute addCouponAttribute(CouponAttribute couponAttribute) {
		getCouponAttributes().add(couponAttribute);
		couponAttribute.setCoupon(this);

		return couponAttribute;
	}

	public CouponAttribute removeCouponAttribute(CouponAttribute couponAttribute) {
		getCouponAttributes().remove(couponAttribute);
		couponAttribute.setCoupon(null);

		return couponAttribute;
	}

    public List<CouponMerchant> getCouponMerchants() {
        return couponMerchants;
    }

    public void setCouponMerchants(List<CouponMerchant> couponMerchants) {
        this.couponMerchants = couponMerchants;
    }

    public List<CouponDetail> getCouponDetails() {
		return this.couponDetails;
	}

	public void setCouponDetails(List<CouponDetail> couponDetails) {
		this.couponDetails = couponDetails;
	}

	public CouponDetail addCouponDetail(CouponDetail couponDetail) {
		getCouponDetails().add(couponDetail);
		couponDetail.setCoupon(this);

		return couponDetail;
	}

	public CouponDetail removeCouponDetail(CouponDetail couponDetail) {
		getCouponDetails().remove(couponDetail);
		couponDetail.setCoupon(null);

		return couponDetail;
	}

	public List<CouponRule> getCouponRules() {
		return this.couponRules;
	}

	public void setCouponRules(List<CouponRule> couponRules) {
		this.couponRules = couponRules;
	}

	public CouponRule addCouponRule(CouponRule couponRule) {
		getCouponRules().add(couponRule);
		couponRule.setCoupon(this);

		return couponRule;
	}

	public CouponRule removeCouponRule(CouponRule couponRule) {
		getCouponRules().remove(couponRule);
		couponRule.setCoupon(null);

		return couponRule;
	}
    public List<CouponExclude> getCouponExcludes() {
        return this.couponExcludes;
    }

    public void setCouponExcludes(List<CouponExclude> couponExcludes) {
        this.couponExcludes = couponExcludes;
    }

    public CouponExclude addCouponRuleExclude(CouponExclude couponExclude) {
        getCouponExcludes().add(couponExclude);
        couponExclude.setCoupon(this);

        return couponExclude;
    }

    public CouponExclude removeCouponRuleExclude(CouponExclude couponExclude) {
        getCouponExcludes().remove(couponExclude);
        couponExclude.setCoupon(null);

        return couponExclude;
    }

    @Override
    public String toString() {
	    return String.format("%d-%s(%s)",couponId,couponName,couponDescription);
    }
/*public List<InsuranceGiftwrapItem> getInsuranceGiftwrapItems() {
		return insuranceGiftwrapItems;
	}

	public void setInsuranceGiftwrapItems(List<InsuranceGiftwrapItem> insuranceGiftwrapItems) {
		this.insuranceGiftwrapItems = insuranceGiftwrapItems;
	}*/

    public BigInteger getBonusPoints() {
        return bonusPoints;
    }

    public void setBonusPoints(BigInteger bonusPoints) {
        this.bonusPoints = bonusPoints;
    }

	public String getAuthStatus() {
		return authStatus;
	}

	public void setAuthStatus(String authStatus) {
		this.authStatus = authStatus;
	}
}